<template>
	<div>
    <Content>
      <Form inline>
        <FormItem>
          <Input style="width: 400px" v-model="keywords" search enter-button placeholder="请输入手机号或姓名" @on-search="searchGet" @submit.native.prevent/>
        </FormItem>
        <FormItem>
          <Button @click="reset">重置</Button>
        </FormItem>
      </Form>
      <Table border :columns="columns" :data="dataGrid" @on-selection-change="Selector"></Table>
      <HigPager v-model="query" :total="pageTotal" :init="Init"></HigPager>
      <Button type="primary" @click="Submit">提交</Button>
    </Content>
  </div>  
</template>
<script scope>
export default {
  props: {
    callbank: Function
  },
  data () {
    return {
      pageTotal: 0,
      dataGrid:[],
      keywords: null,
      userArray: [],
      query: {
        pageIndex: 1,
        pageSize: 15
      },
      columns: [
        {
          title: "序号",
          key: "userId",
          fixed: "left",
          width: 80,
          type: "selection",
        },
        {
          title: "用户姓名",
          key: "userName",
        },
        {
          title: "联系电话",
          key: "unionMobile",
        },
        {
          title: "注册时间",
          key: "postTime",
          width: 180,
          render: (h, params) => {
            return h("div", this.$date(params.row.postTime,'yyyy-MM-dd HH:mm'));
          },
        }
      ]
    }
  },
  components: {
    
  },
  methods: {
    //获取列表
    Init() {
      new this.$rest({
        gateway: 'agrobiz',
        service: 'agrobiz-uc',
        url: '/v1.0/view/union/user/plus/page',
        query: this.query,
        action: (res) => {
          if (res.data.code === 20000) {
            this.pageTotal = res.data.data.count
            this.dataGrid = res.data.data.list
            for(let item of this.dataGrid) {
              item.userName = item.userName ? item.userName : '匿名用户'
              item.unionMobile = this.$phone(item.unionMobile)
            }
          } else {
            this.$Message.error(res.data.msg)
          }
        }
      }).get()
    },
    Submit() {
      this.callbank(this.userArray[0])
    },
    Selector(selection) {
      console.log(selection)
      this.userArray = selection
    },
     //搜索
    searchGet() {
      let sqlLike = {
        fields: ["user_name","union_mobile"],
        keyword: this.keywords,
      }
      this.query.sqlLike = sqlLike
      this.query.pageIndex = 1
      this.Init()
    },
    //重置
    reset() {
      delete this.query.sqlLike
      this.keywords = null
      this.Init()
    },
  },
  created(){
    
  }
}
</script>